package as.myapplication;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import as.myapplication.adapter.DialogLVAdapter;

/**
 * Created by liqm on 2017/7/6.
 */

public class MylistItems extends LinearLayout {

    private List list;
    private ListView listView;

    String works;
    private TextView type1;
    private TextView describe1;
    private LinearLayout timell;
    private LinearLayout dealll;
    private TextView type2;
    private TextView type3;
    private TextView describe2;
    private TextView describe3;
    private LinearLayout worksll;
    private List dealData;
    public static String data;

    public MylistItems(Context context) {
        this(context,null,0);
    }

    public MylistItems(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public MylistItems(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        //列表的数据
        list = new ArrayList();
        for (int i = 0; i < 18 ; i++) {
            list.add("工单"+i);
        }

        //处理情况
        dealData = new ArrayList();
        dealData.add("1.按照要求检查机器外观。");
        dealData.add("2.协助银行按照相机");
        initView(context);
    }

    private void initView(Context context) {
       View view =LayoutInflater.from(context).inflate(R.layout.items, null);
        timell = (LinearLayout) view.findViewById(R.id.times);
        dealll = (LinearLayout) view.findViewById(R.id.deal);
        type1 = (TextView) view.findViewById(R.id.type1);
        type2 = (TextView) view.findViewById(R.id.type2);
        type3 = (TextView) view.findViewById(R.id.type3);

        describe1 = (TextView) view.findViewById(R.id.describe);
        describe2 = (TextView) view.findViewById(R.id.describe2);
        describe3 = (TextView) view.findViewById(R.id.describe3);
        LinearLayout.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        addView(view);

        worksll = (LinearLayout) view.findViewById(R.id.works);
        initEvent();
    }
    private void initEvent() {
        worksll.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                final Dialog dialog = new Dialog(getContext());
                dialog.setContentView(R.layout.dialog_content);
                listView = (ListView) dialog.findViewById(R.id.list);
                listView.setAdapter(new DialogLVAdapter(getContext(), list));
                int size = list.size();
                dialog.show();
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        LinearLayout llview = (LinearLayout) view;
                       TextView textView = (TextView) llview.findViewById(R.id.tv);
                        works = textView.getText().toString();
                        describe1.setText(works);
                        dialog.dismiss();
                    }
                });
            }
        });

        dealll.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                data = "";
                final Dialog dialog = new Dialog(getContext());
                dialog.setContentView(R.layout.dialog_content);
                listView = (ListView) dialog.findViewById(R.id.list);
                listView.setAdapter(new DialogLVAdapter(getContext(), dealData));
                dialog.show();
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                        LinearLayout llview = (LinearLayout) view;
                        TextView textView = (TextView) llview.findViewById(R.id.tv);
                        data += textView.getText().toString();
                        describe3.setText(data);
                       // dialog.dismiss();
                    }
                });
            }
        });
    }


}
